#ifndef __BACKEND_H__
#define __BACKEND_H__

#include <SymbolTable.h>
#include <string>
#include <netthumb.h>
#include <sstream>

namespace netthumb
{

  // Ejecutable que generara el grafico.
  #define GRAPH_CMD "fdp"

  // preambulo
  #define GRAPH_PREAM_0 "\tcompound=false;\n\tranksep=1;\n\tlabel=\""
  #define GRAPH_PREAM_1 "\";\n\tnode [shape=plaintext, fontsize=8];\n\tbgcolor=white;\n\tedge [arrowsize=0.5, color=black];"

  // Icono para los nodos 'host'
  #define HOST_ICON "[label=\"\", shape=box, color=\"white\", shapefile=\"images/Computers.png\"]"

  // Icono para los nodos 'router'
  #define ROUTER_ICON "[label=\"\", shape=box, color=\"white\", shapefile=\"images/router.png\"]"

  // Icono para los nodos 'nic'
  #define NIC_ICON "[label=\"\", shape=box, color=\"white\", shapefile=\"images/nic.png\"]"

  // Icono para los nodos 'net'
  #define NET_ICON "[label=\"\", shape=box, color=\"white\", shapefile=\"images/net.png\"]"

  // Atributos para la declaracion de clusters
  #define CLUSTER_ATTR "fontsize=8; color=\"white\"; labelloc=\"b\"; rankdir=TB"

  // Atributos para los enlaces
  #define LINK_ATTR "arrowhead=\"none\""

  // Preambulo para la generacion de tablas de redes.
  #define NET_TABLE_PREAM "\\begin{tabular}{|c|c|c|c|c|}\\hline\n\\textbf{NETWORK} & \\textbf{ADDR} & \\textbf{TYPE} & \\textbf{MTU} & \\textbf{MULTICAST}\\\\\\hline\n"

  // Preambulo para la generacion de tablas de rutas.
  #define ROUTE_TABLE_PREAM "\\begin{tabular}{|c|c|c|c|c|c|c|c|}\\hline\n\\textbf{HOST} & \\textbf{DEVICE} & \\textbf{NET} & \\textbf{VIA} & \\textbf{PRIORITY} & \\textbf{METRIC} & \\textbf{TYPE} & \\textbf{DEF}\\\\\\hline\n"

  class BackendI {

  private:
    string _fileName;
    SymbolTable& _sTable;
    const string& _outType;
    ostringstream _linkStream;
    ostringstream _dotStream;
    ostringstream _nTContentStream;
    ostringstream _rTContentStream;

    string generateHosts();
    string generateRouters();
    string generateNets();
    void makeTables();
    void generateRouteLines(string host, RouteI* route);
    string generateDevice(string devName, string systemName, DeviceI* device);
    string generateDevicesFromRouter(string routerName);
    string generateDevicesFromHost(string hostName);

  public:
    
    BackendI(const string& fileName,
	     const string& outType,
	     SymbolTable& sTable);

    void makeGraph();
    void genCmdFile(const string& fileName);
  };
}

#endif
